//                            _ooOoo_  
//                           o8888888o  
//                           88" . "88  
//                           (| -_- |)  
//                            O\ = /O  
//                        ____/`---'\____  
//                      .   ' \\| |// `.  
//                       / \\||| : |||// \  
//                     / _||||| -:- |||||- \  
//                       | | \\\ - /// | |  
//                     | \_| ''\---/'' | |  
//                      \ .-\__ `-` ___/-. /  
//                   ___`. .' /--.--\ `. . __  
//                ."" '< `.___\_<|>_/___.' >'"".  
//               | | : `- \`.;`\ _ /`;.`/ - ` : | |  
//                 \ \ `-. \_ __\ /__ _/ .-` / /  
//         ======`-.____`-.___\_____/___.-`____.-'======  
//                            `=---='  
//  
//         .............................................  
//                  佛祖保佑             永无BUG 
//          佛曰:  
//                  写字楼里写字间，写字间里程序员；  
//                  程序人员写程序，又拿程序换酒钱。  
//                  酒醒只在网上坐，酒醉还来网下眠；  
//                  酒醉酒醒日复日，网上网下年复年。  
//                  但愿老死电脑间，不愿鞠躬老板前；  
//                  奔驰宝马贵者趣，公交自行程序员。  
//                  别人笑我忒疯癫，我笑自己命太贱；  
//                  不见满街漂亮妹，哪个归得程序员？  

#include "PlayerInfo.h"

PlayerInfo::PlayerInfo(){
	//用户id
	userId =0;
	//角色id
	roleId =0;
	//等级
	level =0;
	//当前经验
	firstExp =0;
	//角色名称
	roleName = "";
	//银币
	money =0;
	//元宝
	dollar =0;
	//声望
	shengwang =0;
	//荣誉
	rongyu =0;
	//所属门派
	playerType =0;
	//剩余挑战boss次数
	fightBossNum = 0;
	//剩余快速战斗次数
	celerityNum = 0;
	//剩余打造次数
	firstEquipNum = 0;
	//剩余团队竞技次数
	teamFightNum = 0;
	//剩余个人竞技次数
	areaFightNum = 0;
	//剩余兑换银币次数
	exchangeMoneyNum = 0;
	//剩余购买boss次数
	firstBuyBossNum = 0;
	//最大购买boss次数
	maxFirstBuyBossNum = 0;
	//最大挑战boss次数
	maxFightBossNum = 0;
	//最大快速战斗次数
	maxCelerityNum = 0;
	//最大打造次数
	maxFirstEquipNum = 0;
	//最大团队竞技次数
	maxTeamFightNum = 0;
	//最大个人竞技次数
	maxAreaFightNum = 0;
	//最大兑换银币次数
	maxExchangeMoneyNum = 0;
	//vip当前经验
	vimFirstExp =0;
	//vip当前等级
	vimFirstLv = 0;
	//最大组别
	fightTeam =0;
	//当前战斗副本
	fightMapId =0;
	//添加资质属性点
	aptitudeNum = 0;
	//玩家的装备熔炼值
	equipValues =0;
	//是否有帮派0否1是
	isGang = 0;
	//用户账号
	playerUserName = "";
	//熊猫刷新token
	xmrefrensToken = "";
}

PlayerInfo::~PlayerInfo()
{
	reset();
}

PlayerInfo* PlayerInfo::clone(){
	auto ret=new  PlayerInfo();
ret->userId=userId;
ret->roleId=roleId;
ret->level=level;
ret->firstExp=firstExp;
ret->roleName=roleName;
ret->money=money;
ret->dollar=dollar;
ret->shengwang=shengwang;
ret->rongyu=rongyu;
ret->playerType=playerType;
ret->fightBossNum=fightBossNum;
ret->celerityNum=celerityNum;
ret->firstEquipNum=firstEquipNum;
ret->teamFightNum=teamFightNum;
ret->areaFightNum=areaFightNum;
ret->exchangeMoneyNum=exchangeMoneyNum;
ret->firstBuyBossNum=firstBuyBossNum;
ret->maxFirstBuyBossNum=maxFirstBuyBossNum;
ret->maxFightBossNum=maxFightBossNum;
ret->maxCelerityNum=maxCelerityNum;
ret->maxFirstEquipNum=maxFirstEquipNum;
ret->maxTeamFightNum=maxTeamFightNum;
ret->maxAreaFightNum=maxAreaFightNum;
ret->maxExchangeMoneyNum=maxExchangeMoneyNum;
ret->vimFirstExp=vimFirstExp;
ret->vimFirstLv=vimFirstLv;
ret->fightTeam=fightTeam;
ret->fightMapId=fightMapId;
ret->aptitudeNum=aptitudeNum;
ret->equipValues=equipValues;
ret->isGang=isGang;
ret->playerUserName=playerUserName;
ret->xmrefrensToken=xmrefrensToken;
for(auto bean : drawGiftIds){
	ret->drawGiftIds.push_back(bean);
}
for(auto bean : propUseNum){
		ret->propUseNum.push_back(bean->clone());
}
for(auto bean : firstPlay){
		ret->firstPlay.push_back(bean->clone());
}
for(auto bean : otherStatus){
	ret->otherStatus.push_back(bean);
}
return ret;
}

void PlayerInfo::reset(){
for(auto bean : drawGiftIds){
}
drawGiftIds.clear();
for(auto bean : propUseNum){
	if (bean)
	delete bean;
	bean=0;
}
propUseNum.clear();
for(auto bean : firstPlay){
	if (bean)
	delete bean;
	bean=0;
}
firstPlay.clear();
for(auto bean : otherStatus){
}
otherStatus.clear();
}
/**
 * 读取字节缓存
 */
bool PlayerInfo::read_from(ByteBuf& buf)
{
	//用户id
	userId = readInt64(buf);
	//角色id
	roleId = readInt64(buf);
	//等级
	level = readInt32(buf);
	//当前经验
	firstExp = readInt32(buf);
	//角色名称
	roleName = readString(buf, roleName);
	//银币
	money = readInt32(buf);
	//元宝
	dollar = readInt32(buf);
	//声望
	shengwang = readInt32(buf);
	//荣誉
	rongyu = readInt32(buf);
	//所属门派
	playerType = readInt32(buf);
	//剩余挑战boss次数
	fightBossNum = readInt8(buf);
	//剩余快速战斗次数
	celerityNum = readInt8(buf);
	//剩余打造次数
	firstEquipNum = readInt8(buf);
	//剩余团队竞技次数
	teamFightNum = readInt8(buf);
	//剩余个人竞技次数
	areaFightNum = readInt8(buf);
	//剩余兑换银币次数
	exchangeMoneyNum = readInt8(buf);
	//剩余购买boss次数
	firstBuyBossNum = readInt8(buf);
	//最大购买boss次数
	maxFirstBuyBossNum = readInt8(buf);
	//最大挑战boss次数
	maxFightBossNum = readInt8(buf);
	//最大快速战斗次数
	maxCelerityNum = readInt8(buf);
	//最大打造次数
	maxFirstEquipNum = readInt8(buf);
	//最大团队竞技次数
	maxTeamFightNum = readInt8(buf);
	//最大个人竞技次数
	maxAreaFightNum = readInt8(buf);
	//最大兑换银币次数
	maxExchangeMoneyNum = readInt8(buf);
	//vip当前经验
	vimFirstExp = readInt32(buf);
	//vip当前等级
	vimFirstLv = readInt8(buf);
	//最大组别
	fightTeam = readInt32(buf);
	//当前战斗副本
	fightMapId = readInt32(buf);
	//添加资质属性点
	aptitudeNum = readInt16(buf);
	//玩家的装备熔炼值
	equipValues = readInt32(buf);
	//是否有帮派0否1是
	isGang = readInt8(buf);
	//用户账号
	playerUserName = readString(buf, playerUserName);
	//熊猫刷新token
	xmrefrensToken = readString(buf, xmrefrensToken);
	//已领取礼包id
	short drawGiftIds_length = readInt16(buf);
	for (int i = 0; i < drawGiftIds_length; i++) {
		drawGiftIds.push_back(readInt16(buf));
	}
	//道具使用数量
	short propUseNum_length = readInt16(buf);
	for (int i = 0; i < propUseNum_length; i++) {
		auto bean =new PropUseNum();
		readBean(buf, *bean);
		propUseNum.push_back(bean);
	}
	//首冲列表
	short firstPlay_length = readInt16(buf);
	for (int i = 0; i < firstPlay_length; i++) {
		auto bean =new FirstPlay();
		readBean(buf, *bean);
		firstPlay.push_back(bean);
	}
	//角色已存在状态标示
	short otherStatus_length = readInt16(buf);
	for (int i = 0; i < otherStatus_length; i++) {
		otherStatus.push_back(readInt32(buf));
	}
	
	return true;
}

/**
 * 写入字节缓存
 */
bool PlayerInfo::write_to(ByteBuf& buf)
{
	//用户id
	writeInt64(buf, userId);
	//角色id
	writeInt64(buf, roleId);
	//等级
	writeInt32(buf, level);
	//当前经验
	writeInt32(buf, firstExp);
	//角色名称
	writeString(buf, roleName);
	//银币
	writeInt32(buf, money);
	//元宝
	writeInt32(buf, dollar);
	//声望
	writeInt32(buf, shengwang);
	//荣誉
	writeInt32(buf, rongyu);
	//所属门派
	writeInt32(buf, playerType);
	//剩余挑战boss次数
	writeInt8(buf, fightBossNum);
	//剩余快速战斗次数
	writeInt8(buf, celerityNum);
	//剩余打造次数
	writeInt8(buf, firstEquipNum);
	//剩余团队竞技次数
	writeInt8(buf, teamFightNum);
	//剩余个人竞技次数
	writeInt8(buf, areaFightNum);
	//剩余兑换银币次数
	writeInt8(buf, exchangeMoneyNum);
	//剩余购买boss次数
	writeInt8(buf, firstBuyBossNum);
	//最大购买boss次数
	writeInt8(buf, maxFirstBuyBossNum);
	//最大挑战boss次数
	writeInt8(buf, maxFightBossNum);
	//最大快速战斗次数
	writeInt8(buf, maxCelerityNum);
	//最大打造次数
	writeInt8(buf, maxFirstEquipNum);
	//最大团队竞技次数
	writeInt8(buf, maxTeamFightNum);
	//最大个人竞技次数
	writeInt8(buf, maxAreaFightNum);
	//最大兑换银币次数
	writeInt8(buf, maxExchangeMoneyNum);
	//vip当前经验
	writeInt32(buf, vimFirstExp);
	//vip当前等级
	writeInt8(buf, vimFirstLv);
	//最大组别
	writeInt32(buf, fightTeam);
	//当前战斗副本
	writeInt32(buf, fightMapId);
	//添加资质属性点
	writeInt16(buf, aptitudeNum);
	//玩家的装备熔炼值
	writeInt32(buf, equipValues);
	//是否有帮派0否1是
	writeInt8(buf, isGang);
	//用户账号
	writeString(buf, playerUserName);
	//熊猫刷新token
	writeString(buf, xmrefrensToken);
	//已领取礼包id
	writeShort(buf, drawGiftIds.size());
	for (int i = 0; i < drawGiftIds.size(); i++) {
		writeInt16(buf, drawGiftIds[i]);
	}
	//道具使用数量
	writeShort(buf, propUseNum.size());
	for (int i = 0; i < propUseNum.size(); i++) {
		writeBean(buf, *propUseNum[i]);
	}
	//首冲列表
	writeShort(buf, firstPlay.size());
	for (int i = 0; i < firstPlay.size(); i++) {
		writeBean(buf, *firstPlay[i]);
	}
	//角色已存在状态标示
	writeShort(buf, otherStatus.size());
	for (int i = 0; i < otherStatus.size(); i++) {
		writeInt32(buf, otherStatus[i]);
	}
	
	return true;
}
